﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using Refactored.Models;

namespace Refactored.Models
{
    // You can add custom code to this file. Changes will not be overwritten.
    // 
    // If you want Entity Framework to drop and regenerate your database
    // automatically whenever you change your model schema, add the following
    // code to the Application_Start method in your Global.asax file.
    // Note: this will destroy and re-create your database with every model change.
    // 
    // System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseIfModelChanges<Default.Models.BookListContext>());
    public class BookContext : DbContext
    {
        public BookContext()
            : base("name=DefaultConnection")
        {
            Database.SetInitializer<BookContext>(new NetBooksInitializer());
        }

        public DbSet<Book> Books { get; set; }
        public DbSet<UserProfile> Users { get; set; }
    }

    public class NetBooksInitializer : DropCreateDatabaseAlways<BookContext>
    {
        protected override void Seed(BookContext context)
        {

            var books = new List<Book>();

            books.Add(new Book { Title = "The Goldfinch", Author = "Donna Tartt", Description = "This is both the heart-wrenching story of Theo Decker, a man who lost his mother as a boy in a freak accident, as well as a globe-spanning mystery about a painting that has gone missing. The 700+ page book has a moving plot and urgency that is impossible to resist.", Creator = "" });
            books.Add(new Book { Title = "And The Mountains Echoed", Author = "Khaled Hosseini", Description = "From the author of \"The Kite Runner\" and \"A Thousand Splendid Suns\" comes the tale of a brother and sister separated after their father sells the girl to a wealthy couple in Kabul, Afghanistan. Told through multiple viewpoints over half a century, the book follows the brother and sister through wars, births, deaths, deceit, and love.", Creator = "" });
            books.Add(new Book { Title = "Thank You for Your Service", Author = "David Finkel", Description = "This nonfiction book is a poignant, eye-opening collection of interviews with soldiers returning home from combat with shattered bodies and minds. An incredibly important read, it's impossible to remain unaffected by their struggles and slow readjustment to civilian life.", Creator = "" });
            books.Add(new Book { Title = "Life After Life", Author = "Kate Atkinson", Description = "What if you could die and be reborn again? That's the case with Ursula Todd, the star character of this brilliant, multi-layered novel. With the backdrop of London during WWII, \"Life After Life\" is funny, philosophical, and powerful as it follows the consequences of Ursula's time-bending ability on her family, friends, and the 20th-century.", Creator = "" });
            books.Add(new Book { Title = "Pilgrim's Wilderness", Author = "Tom Kizzia", Description = "This is the true story of a family that seemed to be living a pious life in an Alaskan ghost town until its revealed there's a dark underbelly beneath their sweet veneer — FBI files, physical and sexual abuse, brainwashing, and violent deaths. Tom Kizzia, a reporter for Anchorage Daily News, dives into the the murky waters of this family's past.", Creator = "" });
            books.Add(new Book { Title = "Lawrence in Arabia", Author = "Scott Anderson", Description = "\"Lawrence in Arabia\" follows the four low-ranking men who all shaped the Middle East through battles, spying, and scheming during the first World War. Based on intensive research, it's hard not to get caught up in these sweeping conflicts that still influence the world today.", Creator = "" });
            books.Add(new Book { Title = "Tenth of December", Author = "George Saunders", Description = "Saunders’ first collection of short stories in six years introduces his ironic, absurd, profound and funny style to an army of new readers.", Creator = "" });
            books.Add(new Book { Title = "The Son", Author = "Philipp Meyer", Description = "A multigenerational Western spanning the 1800s Comanche raids in Texas to the 20th century oil boom, The Sonis a towering achievement.", Creator = "" });
            books.Add(new Book { Title = "A House in the Sky: A Memoir", Author = "Amanda Lindhout", Description = "Written with uncommon sensitivity, Lindhout’s account of the 460 days she spent as a captive in Somalia is a moving testament to human resilience in the midst of profound darkness.", Creator = "" });
            books.Add(new Book { Title = "Eleanor & Park", Author = "Rainbow Rowell", Description = "This young adult novel about two kids who fall in love on a bus is sweet without being saccharine. And it’s a story adults can love, too.", Creator = "" });
            
            foreach (var book in books)
            {
                context.Books.Add(book);
            }

            context.SaveChanges();
        }
    }
}